package cn.kgc.novel.service.impl;

import cn.kgc.novel.mapper.BookcontextMapper;
import cn.kgc.novel.mapper.BooksMapper;
import cn.kgc.novel.pojo.Bookcontext;
import cn.kgc.novel.pojo.Books;
import cn.kgc.novel.service.BookcontextService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List;
//杨将
@Service
public class BookcontextServiceImpl implements BookcontextService {

    public BookcontextServiceImpl() {

    }

    @Resource
    private BookcontextMapper bookcontextMapper;
    @Resource
    private BooksMapper booksMapper;
    //重写跟据小说名和作者id查数据
    @Override
    public List<Bookcontext> selectshow(String bookname, Integer uid) {
        System.out.println("service:"+bookname+uid);
        return bookcontextMapper.selectshows(bookname,uid);
    }
    //跟据章节和小时名称那内容
    @Override
    public Bookcontext flieshow(int titleid,String bookname) {
        Bookcontext flieshows = bookcontextMapper.flieshows(titleid, bookname);
        return flieshows;
    }
    @Override
    public Integer naid(String name) {
        return bookcontextMapper.naid(name);
    }
    //拿最近更新的章节
    @Override
    public List<Bookcontext> nazhanges(String category,String sex) {
        return  bookcontextMapper.nazhanges(category,sex);
    }


    @Override
    public void addBookcontext(Bookcontext bookcontext) {
        bookcontextMapper.addBookcontext(bookcontext);
    }
    //更据书的id和作者id来查询 这本书未发布的草稿章节
    @Override
    public List<Bookcontext> draftchapter(Integer bid, Integer uid,Integer titleid) {
        return bookcontextMapper.draftchapter(bid, uid,titleid);
    }

    @Override
    public void updatedraftchapter(Integer bid, Integer uid, Integer titleid) {
        bookcontextMapper.updatedraftchapter(bid, uid, titleid);
        //查找这本书有没有被发布，没有的话连同书一同发布，有的话就跳过-武龙
        List<Books> unpublished = booksMapper.unpublished(uid);
        System.out.println("unpublished的大小："+unpublished.size());
        Iterator<Books> iterator = unpublished.iterator();
        while(iterator.hasNext()){
            System.out.println("进入了iterator循环中");
            Books next = iterator.next();
            System.out.println("next.getBid()：{}"+next.getBid());
            if(bid.equals(next.getBid())){
                System.out.println("发布了书籍");
                booksMapper.updateStatus(bid);
            }
        }
    }

    @Override
    public void updateBookcontext(Bookcontext bookcontext) {
        System.out.println("service:中的"+bookcontext);
        bookcontextMapper.updateBookcontext(bookcontext);
    }

    @Override
    public int deletecaogao(Integer uid, Integer bid, Integer titleid) {
        return bookcontextMapper.deletecaogao(uid,bid,titleid);
    }

    //查看所有未审核的章节,袁宇灏
    @Override
    public List<Bookcontext> findByStatuc() {

        return bookcontextMapper.getByStatuc();
    }
    //通过cid查找
    @Override
    public List<Bookcontext> findByCid(Integer cid) {
        return bookcontextMapper.getByCid(cid);
    }
    // 2023-11-23 审核
    @Override
    public void audit(String status,Integer cid,String reason) {
        bookcontextMapper.setStatus(status,cid,reason);
    }

    @Override
    public void deleteBookcontext(int authorid, int bid) {
        bookcontextMapper.deleteBookcontext(authorid,bid);
    }



}
